package com.example.analysis.controller;

import com.example.analysis.entity.*;
import com.example.analysis.entity.Class;
import com.example.analysis.service.*;
import com.example.analysis.utils.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/file")
public class ExcelUpdate {
    @Resource
    private ClassService classService;
    @Resource
    private CollegeService collegeService;
    @Resource
    private MajorService majorService;
    @Resource
    private CourseService courseService;
    @Resource
    private StudentService studentService;
    @Resource
    private CompeteService competeService;
    @Resource
    private ElectionService electionService;
    @Resource
    private TeacherService teacherService;
    @Resource
    private EvaluateListStudentService evaluateListStudentService;
    @Resource
    private TeacherCourseClassService teacherCourseClassService;
    @Resource
    private SupervisionService supervisionService;
    @Resource
    private EvaluateSupervisionService evaluateSupervisionService;
    @Resource
    private CompetitionListService competitionListService;

    public String getMajorId01(String major){
        String temp=major.replaceAll("\\d.*", "");
        if(temp.equals("物联网")){
            temp="物联";
        }
        return temp;
    }
    public static List<Double> generateGrades(double score) {
        List<Double> grades = new ArrayList<>();

        // 计算期末成绩的范围
        double finalMin = Math.max(0.0, (score - 40) / 0.6);
        double finalMax = Math.min(100.0, score / 0.6);

        // 检查是否有有效解
        if (finalMin > finalMax) {
            throw new IllegalArgumentException("总成绩不在有效范围内，无法生成合法成绩");
        }

        // 取期末成绩的中间值（也可改为其他取值方式）
        double finalGrade = (finalMin + finalMax) / 2.0;
        // 计算期中和平时的总和
        double sumMidDaily = 5.0 * (score - 0.6 * finalGrade);
        // 均分给期中和平时的成绩
        double midGrade = sumMidDaily / 2.0;
        double dailyGrade = sumMidDaily - midGrade;

        grades.add(finalGrade);
        grades.add(midGrade);
        grades.add(dailyGrade);

        return grades;
    }


    /**
     * 成绩信息
     * @param file
     * @return
     */
    @PostMapping("/fileUpdate")
    public Response1 fileUpdate(MultipartFile file) {
        if(file==null){
            System.out.println("文件为空");
        }
        Map<String,Object> res = new HashMap<>();
        //导入Class表
        int count=325;
        List<MessageInfo> messageList = ExcelUtils.getExcelInfo(file);
//        /** 教师表 */
//        for (MessageInfo messageInfo:messageList){
//            Response<Teacher> studentResponse = teacherService.getById(messageInfo.getTeacherId());
//            Teacher studentInfo=new Teacher();
//            if(!studentResponse.isSuccess() && messageInfo.getTeacherId()!=null){
//                studentInfo.setTeacherId(messageInfo.getTeacherId());
//                studentInfo.setTeacherName(messageInfo.getTeacherName());
//                studentInfo.setPwd("123456");
//                System.out.println(studentInfo);
//                Response<Teacher> response=teacherService.insert(studentInfo);
//                System.out.println(response);
//            }
//        }
//        /** 班级表*/
//        for(MessageInfo messageInfo: messageList){
//            Response<Class> classResponse = classService.getByName(messageInfo.getClas());
//            Class classInfo=new Class();
//            if(!classResponse.isSuccess()){
//                classInfo.setClassId("class"+String.valueOf(count));
//                count++;
//                classInfo.setClassName(messageInfo.getClas());
//                Response<Class> response=classService.insert(classInfo);
//                System.out.println(response);
//            }
//        }
//        /** 课程表*/
//        for(MessageInfo messageInfo: messageList){
//            Response<Course> courseResponse = courseService.getById(messageInfo.getCourse_id());
//            Course courseInfo=new Course();
//            if(!courseResponse.isSuccess()){
//                courseInfo.setSubId(messageInfo.getCourse_id());
//                courseInfo.setSubName(messageInfo.getCourse_name());
//                courseInfo.setSubTime(messageInfo.getSub_time());
//                courseInfo.setSubAttribute(messageInfo.getCour_att());
//                courseInfo.setSubCode(messageInfo.getSub_sore());
//                Response<Course> response=courseService.insert(courseInfo);
//                System.out.println(response);
//            }
//        }
//        /** 学生表*/
//        for (MessageInfo messageInfo:messageList){
//            Response<Student> studentResponse = studentService.getById(messageInfo.getStud_id());
//            Student studentInfo=new Student();
//            if(!studentResponse.isSuccess()){
//                studentInfo.setStudentId(messageInfo.getStud_id());
//                studentInfo.setName(messageInfo.getStud_name());
//                studentInfo.setPwd("123456");
//                studentInfo.setClassId(classService.getByName(messageInfo.getClas()).getData().getClassId());
//                studentInfo.setMajorId(majorService.getByName(getMajorId01(messageInfo.getClas())).getData().getMajorId());
//                Response<Student> response=studentService.insert(studentInfo);
//                System.out.println(response);
//            }
//        }
        /** 成绩信息表*/
        for(MessageInfo messageInfo:messageList){
            Response<Election> electionListResponse=electionService.getById(messageInfo.getCourse_id(),messageInfo.getStud_id());
            Election election=new Election();
            if(!electionListResponse.isSuccess()){
                if(messageInfo.getScore()==0||messageInfo.getScore()==null){
                    continue;
                }
                election.setStudentId(messageInfo.getStud_id());
                election.setSubId(messageInfo.getCourse_id());
                election.setScore(messageInfo.getScore());
                election.setSemester(messageInfo.getSemester());
                List<Double> grades = generateGrades(messageInfo.getScore());
                //平时成绩
                if (grades.get(0)==0){
                    continue;
                }
                election.setEnd_score((double) Math.round(grades.get(0)));
                election.setHalf_score((double) Math.round(grades.get(1)));
                election.setDay_score((double) Math.round(grades.get(2)));
                election.setPro_score(60.0);
                election.setPro_half(20.0);
                election.setPro_day(20.0);
                Response<Election> response=electionService.insert(election);
            }
        }
        return new Response1<>(20000,"录入成功");
    }

    /**
     * 学生评教信息
     * @param file
     * @return
     */
    @PostMapping("/fileUpdate2")
    public String fileUpdate2(MultipartFile file){
        List<Compete> competeList= ComExcelUtils.getExcelInfo(file);
        int num=1;
        //导入竞赛表
        for (Compete compete: competeList){
            Response<Competition> competitionResponse=competeService.getByName(compete.getComName(),compete.getType());
            Competition competition=new Competition();
            if(!competitionResponse.isSuccess()){
                competition.setCompetitionId("competition"+num);
                num++;
                competition.setCompetitionName(compete.getComName());
                competition.setCompetitionType(compete.getType());
                Response<Competition> response=competeService.insert(competition);
                System.out.println(response);
            }
        }
        //导入竞赛记录表
        for(Compete compete:competeList){
            //处理数据
            String str=compete.getPeo();
            String[] parts = str.split(":");
            String str2=compete.getPeo2();
            if(!str2.isEmpty()){//有队员进入
                String result = str+','+str2;
                Response<Competition> competitionResponse=competeService.getByName(compete.getComName(),compete.getType());
                if(competitionResponse.isSuccess()){
                    CompetitionList competitionList=new CompetitionList();
                    competitionList.setCompetitionId(competitionResponse.getData().getCompetitionId());
                    competitionList.setStudentId(parts[1].replace("\t",""));
                    if(compete.getWin().contains("是")){
                        competitionList.setAward(true);
                        competitionList.setEntrants(result);
                        competitionList.setAwards(compete.getAwards());
                        Response<CompetitionList> response=competitionListService.insert(competitionList);
                        System.out.println(response);
                    }
                    else{
                        competitionList.setAward(false);
                        competitionList.setEntrants(str);
                        Response<CompetitionList> response=competitionListService.insert(competitionList);
                        System.out.println(response);
                    }
                }
            }
        }
        return "finish";
    }

    /**
     * 真实的学生成绩信息
     * @param file
     * @return
     */
    @PostMapping("/fileUpdate3")
    public String fileUpdate3(MultipartFile file){
        //导入Class表
        int count=1;
        if(file== null){
            return "文件不能为空";
        }
        List<MessageInfo> messageList = ExcelUtils2.getExcelInfo(file);
        for(MessageInfo messageInfo: messageList){
            Response<Class> classResponse = classService.getByName(messageInfo.getClas());
            Class classInfo=new Class();
            if(!classResponse.isSuccess()){
                classInfo.setClassId("class"+String.valueOf(count));
                classInfo.setClassName(messageInfo.getClas());
                count++;
                classService.insert(classInfo);
            }
        }
        //课程表
        for(MessageInfo messageInfo: messageList){
            Response<Course> courseResponse = courseService.getByName(messageInfo.getCourse_name());
            Course courseInfo=new Course();
            if(!courseResponse.isSuccess()){
                courseInfo.setSubId(messageInfo.getCourse_id());
                courseInfo.setSubName(messageInfo.getCourse_name());
                courseService.insert(courseInfo);
            }
        }
        count=10;
        for (MessageInfo messageInfo:messageList){
            Response<Major> classResponse = majorService.getByName(getMajorId01(messageInfo.getClas()));
            Major major=new Major();
            if(!classResponse.isSuccess()){
                major.setMajorId("major"+count);
                count++;
                major.setMajorName(getMajorId01(messageInfo.getClas()));
                major.setCollegeId("college1");
                majorService.insert(major);
            }
        }
        //学生表
        for (MessageInfo messageInfo:messageList){
            Response<Student> studentResponse = studentService.getById(messageInfo.getStud_id());
            Student studentInfo=new Student();
            if(!studentResponse.isSuccess()){
                studentInfo.setStudentId(messageInfo.getStud_id());
                studentInfo.setName(messageInfo.getStud_name());
                studentInfo.setPwd("123456");
                studentInfo.setClassId(classService.getByName(messageInfo.getClas()).getData().getClassId());
                studentInfo.setMajorId(majorService.getByName(getMajorId01(messageInfo.getClas())).getData().getMajorId());
                studentService.insert(studentInfo);
            }
        }
        //学生选课表
        for(MessageInfo messageInfo:messageList){
            Response<Election> electionListResponse=electionService.getById(messageInfo.getCourse_id(),messageInfo.getStud_id());
            Election election=new Election();
            if(!electionListResponse.isSuccess()){
                election.setStudentId(messageInfo.getStud_id());
                election.setSubId(messageInfo.getCourse_id());
                election.setScore(messageInfo.getScore());
                Double temp=messageInfo.getScore();
                //平时成绩
                election.setExper_score(messageInfo.getScore1());
                election.setDay_score(messageInfo.getScore2());
                election.setHalf_score(messageInfo.getScore3());
                election.setPro_score(messageInfo.getPro_score());
                election.setPro_ex(messageInfo.getPro_score1());
                election.setPro_day(messageInfo.getPro_score2());
                election.setPro_half(messageInfo.getPro_score3());
                Response<Election> response=electionService.insert(election);
                System.out.println(election);
                System.out.println(response);
            }
        }
        return "finish";
    }

    /**
     * 学科竞赛成绩
     * @param file
     * @return
     */
    @PostMapping("/fileUpdate4")
    public String fileUpdate4(MultipartFile file){
        if(file==null){
            return "文件不能为空";
        }
        List<Evaluate1> evaluate1List = ExcelUtils3.getExcelInfo(file);
//        //先把课程录入
//        for (Evaluate1 evaluate1: evaluate1List){//课程表
//            Response<Course> courseResponse = courseService.getById(evaluate1.getCourseId());
//            Course courseInfo=new Course();
//            if(!courseResponse.isSuccess()){
//                courseInfo.setSubId(evaluate1.getCourseId());
//                courseInfo.setSubName(evaluate1.getCourseName());
//                Response<Course> response=courseService.insert(courseInfo);
//                System.out.println(response);
//            }
//        }
//        int count=198;
//        //班级
//        for(Evaluate1 messageInfo:evaluate1List){
//            Response<Class> classResponse = classService.getByName(messageInfo.getClassName());
//            Class classInfo=new Class();
//            if(!classResponse.isSuccess()){
//                classInfo.setClassId("class"+String.valueOf(count));
//                classInfo.setClassName(messageInfo.getClassName());
//                count++;
//                classService.insert(classInfo);
//            }
//        }
//        //再把学生录入
//        for (Evaluate1 messageInfo:evaluate1List){
//            Response<Student> studentResponse = studentService.getById(messageInfo.getStudentId());
//            Student studentInfo=new Student();
//            if(!studentResponse.isSuccess()){
//                studentInfo.setStudentId(messageInfo.getStudentId());
//                studentInfo.setName(messageInfo.getStudentName());
//                studentInfo.setPwd("123456");
//                studentInfo.setClassId(classService.getByName(messageInfo.getClassName()).getData().getClassId());
//                studentInfo.setMajorId(majorService.getByName(getMajorId01(messageInfo.getClassName())).getData().getMajorId());
//                Response<Student> response=studentService.insert(studentInfo);
//                System.out.println(response);
//            }
//        }

        //学生评价
        for(Evaluate1 evaluate1:evaluate1List){
            Response<List<Teacher>> response=teacherService.getByName(evaluate1.getTeacherName());
            System.out.println(evaluate1.getTeacherName());
            System.out.println(response);
            if(!response.isSuccess()){ //没找到教师 跳过
                continue;
            }
            //
            if(response.getData().isEmpty()){
                continue;
            }
            String teacherId=response.getData().get(0).getTeacherId();
            Response<List<EvaluateListStudent>> evaluateListStudentResponse=evaluateListStudentService.getById(evaluate1.getStudentId(),evaluate1.getCourseId(),teacherId);
            if(evaluate1.getScore()==null){
                continue;
            }
            //生成数据   没有数据就进行插入
            if(evaluateListStudentResponse.getData().isEmpty()){
                System.out.println("插入新的数据");
                if (evaluate1.getScore().equals(96.0)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.96);//25 A
                        }else{
                            evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(93.9)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.96);//25 A
                        }else{
                            if (i==1){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);

                    }
                }
                else if (evaluate1.getScore().equals(92.5)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(91.8)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.96);//25 A
                        }else{
                            if(i==1||i==2||i==3){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(90.4)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            if(i==1){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }

                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(89.7)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.96);//25 A
                        }else{
                            if(i==1||i==2){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(88.3)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            if(i==1||i==2||i==3){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(87.6)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.96);//25 A
                        }else{
                            if(i==1){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(86.2)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            if(i==1||i==2){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(84.8)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.68);//25 A
                        }else{
                            if(i==1||i==2||i==3){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(84.1)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            if(i==1){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(82.7)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.68);//25 A
                        }else{
                            if(i==1||i==2){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.96 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(82.0)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(79.9)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            if(i==1||i==2||i==3||i==4){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.68 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(78.5)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore((double) Math.round(15.0*0.68 * 100) / 100);//25 A
                        }else{
                            evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(74.3)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.68);//25 A
                        }else{
                            if(i==1||i==2||i==3){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.68 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
                else if (evaluate1.getScore().equals(77.8)){
                    for (int i=1;i<7;i++){
                        EvaluateListStudent evaluateListStudent = new EvaluateListStudent();
                        evaluateListStudent.setSubId(evaluate1.getCourseId());
                        evaluateListStudent.setStudentId(evaluate1.getStudentId());
                        evaluateListStudent.setTeacherId(teacherId);
                        evaluateListStudent.setQuestId(String.valueOf(i));
                        if(i==6){
                            evaluateListStudent.setEvaScore(25.0*0.82);//25 A
                        }else{
                            if(i==1||i==2||i==3){
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.82 * 100) / 100);
                            }else{
                                evaluateListStudent.setEvaScore((double) Math.round(15.0*0.68 * 100) / 100);
                            }
                        }
                        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                        Date date= null;
                        try {
                            date = dateFormat.parse(evaluate1.getEvaTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        evaluateListStudent.setEvaTime(date);
                        evaluateListStudentService.insert(evaluateListStudent);
                    }
                }
            }
            else{
                System.out.println("插入到teacherCourseClass");
                TeacherCourseClass teacherCourseClass=new TeacherCourseClass();
                EvaluateListStudent evaluateListStudent=evaluateListStudentResponse.getData().get(1);
                String classId=studentService.getById(evaluateListStudent.getStudentId()).getData().getClassId();
                teacherCourseClass.setClassId(classId);
                teacherCourseClass.setTeacherId(evaluateListStudent.getTeacherId());
                teacherCourseClass.setCourseId(evaluateListStudent.getSubId());
                Response<TeacherCourseClass> response1=teacherCourseClassService.insert(teacherCourseClass);
                System.out.println(response1);
            }
        }
        return "null";
    }

    @PostMapping("/fileUpdate5")
    public String fileUpdate5(MultipartFile file){

        List<Evaluate2> competeList= ExcelUtils4.getExcelInfo(file);
        //督导  同行  领导导入
        int num=362;
        for (Evaluate2 compete: competeList){
            Response<List<Supervision>> competitionResponse=supervisionService.getByName(compete.getSupervision());
            Supervision competition=new Supervision();
            if(competitionResponse.getData().isEmpty()){
                competition.setSupervisionId("supervision"+num);
                num++;
                competition.setSupervisionName(compete.getSupervision());
                System.out.println(compete.getSupervision());
                competition.setPwd("123456");
                Response<Supervision> response=supervisionService.insert(competition);
                System.out.println(response);
            }
        }
        //教师表
        for (Evaluate2 compete: competeList){
            Response<Teacher> competitionResponse=teacherService.getById(compete.getTeacherId());
            Teacher competition=new Teacher();
            if(!competitionResponse.isSuccess()){
                competition.setTeacherId(compete.getTeacherId());
                competition.setTeacherName(compete.getTeacherName());
                competition.setPwd("123456");
                Response<Teacher> response=teacherService.insert(competition);
                System.out.println(response);
            }
        }
        //课程表
        for (Evaluate2 compete: competeList){
            Response<Course> competitionResponse=courseService.getById(compete.getCourseId());
            Course competition=new Course();
            if(!competitionResponse.isSuccess()){
                competition.setSubId(compete.getCourseId());
                competition.setSubName(compete.getCourseName());
                Response<Course> response=courseService.insert(competition);
                System.out.println(response);
            }
        }
        //督导评价表
        for (Evaluate2 compete: competeList){
            Response<List<Supervision>> response=supervisionService.getByName(compete.getSupervision());
            if(!response.isSuccess()){ //没找到教师 跳过
                continue;
            }
            if(response.getData().isEmpty()){
                continue;
            }
            String supervisionId=response.getData().get(0).getSupervisionId();
            Response<List<EvaluateSupervision>> competitionResponse=evaluateSupervisionService.getById(supervisionId,compete.getCourseId(),compete.getTeacherId());
            EvaluateSupervision competition=new EvaluateSupervision();
            if(competitionResponse.getData().isEmpty()){
                for(int i=7;i<13;i++){
                    competition.setSupervisionId(supervisionId);
                    competition.setSubId(compete.getCourseId());
                    competition.setTeacherId(compete.getTeacherId());
                    if (i==7)
                        competition.setSupervisionScore(compete.getQuest1());
                    if (i==8)
                        competition.setSupervisionScore(compete.getQuest2());
                    if (i==9)
                        competition.setSupervisionScore(compete.getQuest3());
                    if (i==10)
                        competition.setSupervisionScore(compete.getQuest4());
                    if (i==11)
                        competition.setSupervisionScore(compete.getQuest5());
                    if (i==12)
                        competition.setSupervisionScore(compete.getQuest6());
                    competition.setQuestId(String.valueOf(i));
                    SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                    Date date= null;
                    try {
                        date = dateFormat.parse(compete.getEvaTime());
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    competition.setEvaTime(date);
                    Response<EvaluateSupervision> response1=evaluateSupervisionService.insert(competition);
                    System.out.println(response1);
                }
            }
        }

        return "finish";
    }

}
